/*
 * 打印点评记录JS
 * 2018-03-01
 */
var printRecord = (function(){
	//加载打印格式接口
	var loadPrintType = function(rid){
		var def = $.Deferred();
		var url = printUrl + "/printtemprest/findListByRid/" + rid+"?jsessionids="+jsessionids;
		$.ajax({
			type: "GET",
			url: url,
			data:{},
			dataType: "json",
			success: function (resp) {
				def.resolve(resp);
			},
			error : function(XMLHttpRequest, textStatus, errorThrown)
			{
				layer.msg('打印服务器连接失败！',{time : 2000,icon : 3,skin : 'layui-layer-msg3'});
				def.reject();
			}
		});
		return def.promise();
	}
	//打印预览
	var printToView = function(data){
		var rowData = reviewRecord.getParam("review_item");
		if(!rowData){
			layer.msg('请选择要打印的点评记录！',{time : 4000,icon : 0,skin : 'layui-layer-msg0'});
			return false;
		}
		var qaa01 = rowData.qaa01;
		var id = $("#review_print_c").val();
		url = printUrl + "/printtoolrest/printToPdfView/" + id + "?qaa01="+qaa01;
		window.open(url);
	}
	//直接打印
	var printToPdf = function(data){
		debugger;
		var rowData = reviewRecord.getParam("review_item");
		if(!rowData){
			layer.msg('请选择要打印的点评记录！',{time : 4000,icon : 0,skin : 'layui-layer-msg0'});
			return false;
		}
		var qaa01 = rowData.qaa01;
		var id = $("#review_print_c").val();
		url = printUrl + "/printtoolrest/printToPdf/" + id + "?qaa01="+qaa01;
		layer.closeAll();         // 打印前先关闭已经打开 layer 弹框
	    layer.open({
	        type: 2,
	        title:false,          // title 不显示
	        closeBtn: 0,          // 不显示  layer 弹框关闭按钮
	        shadeClose: false,
	        shade: false,
	        area: ['0%', '0%'],   //在页面上不显示
	        content: url,         //iframe的url,
	        success:function(){
	        }
	    });
	}
	
	var printListHtml = function(data){
		var defaultV2,html='';
		for (var i = 0; i < data.length; i++)
		{
			html += '<option value = '+data[i]['id']+'>'+ data[i]['name']+'</option>';
			if (data[i]['xdefault'] == "1")
			{
				defaultV2 = data[i].id;
			}
		}
		$("#review_print_c").empty().append(html);
		if (defaultV2)
		{
			$("#review_print_c").find("select").val(defaultV2).trigger("change");
		}
	}
	 var initInfo = function(){
		 $.when(
				 loadPrintType(111)    //加载打印格式
	    ).done(function (data) {
	    	printListHtml(data);
	    });
     }
     return {
        initInfo:initInfo,
        printToView:printToView,
        printToPdf:printToPdf,
     }
}());
$(function(){
	printRecord.initInfo();
});